<?php
class Project extends CI_Controller{
	function index(){
		$this->load->model('Project_management');
		$data['projects'] = $this->Project_management->getProjects();
		$data['projectCode'] = $this->Project_management->generateProjectCode();
		//$data['main_content'] = 'create_project';
		$data['main_content'] = 'project_management';
		$this->load->view('layouts/general', $data);
	}

	function newProject(){
		$this->load->model('Project_management');
		$data['projects'] = $this->Project_management->getProjects();
		$data['projectCode'] = $this->Project_management->generateProjectCode();
		$data['main_content'] = 'create_project';
		$this->load->view('layouts/general', $data);
	}

	function searchProject(){
		$this->load->model('Project_management');
		$data['projects'] = $this->Project_management->getProject($this->input->post('projectCode'));
		$data['main_content'] = 'project_management';
		$this->load->view('layouts/general', $data);
	}
	function updateProject(){
		$this->load->model('Project_management');
		$data['projects'] = $this->Project_management->getProject($this->input->post('projectCode'));
		$data['stages'] = $this->Project_management->getStages($this->input->post('projectCode'));
		$data['main_content'] = 'project_update';
		$this->load->view('layouts/general', $data);
	}

	function stage(){
		$this->load->model('Project_management');
		$data['stageID'] = $this->Project_management->generateProjectStageID();
		$data['main_content'] = 'create_project_stage';
		$this->load->view('layouts/general', $data);
	}

	function update(){
		$project_data = array(
			'projectCode'=> $this->input->post('projectCode'),
			'title'=>$this->input->post('projectTitle'),
			'customerCode'=>$this->input->post('customerCode'),
			'siteCode'=>$this->input->post('siteCode'),
			'startDate'=>$this->input->post('startDate'),
			'endDate'=>$this->input->post('endDate'),
			'duration'=>$this->input->post('estimatedDuration')
		);
		$this->load->model('Project_management');
		$data['success_message'] = '';
		if($this->Project_management->updateProject($project_data)){			
			$data['success_message'] .= 'You have successfully updated the project!';
		}else{
			$data['success_message'] .= 'Something went wrong while updating the project!';	
		}
		$data['main_content'] = 'success_message';
		$this->load->view('layouts/general',$data);
	}

	function create(){
		$project_data = array(
			'projectCode'=> $this->input->post('projectCode'),
			'title'=>$this->input->post('projectTitle'),
			'customerCode'=>$this->input->post('customerCode'),
			'siteCode'=>$this->input->post('siteCode'),
			'startDate'=>$this->input->post('startDate'),
			'endDate'=>$this->input->post('endDate'),
			'duration'=>$this->input->post('estimatedDuration')
		);
		$this->load->model('Project_management');
		$data['success_message'] = '';
		if($this->Project_management->createProject($project_data)){			
			$data['success_message'] .= 'You have created a new project!';
		}else{
			$data['success_message'] .= 'Something went wrong while creating the project!';	
		}
		$data['main_content'] = 'success_message';
		$this->load->view('layouts/general',$data);
	}

	function createStage(){
		$project_data = array(
			'projectCode'=> $this->input->post('projectCode'),
			'stageID'=>$this->input->post('stageID'),
			'stageName'=>$this->input->post('stageName'),
			'startDate'=>$this->input->post('startDate'),
			'plannedEndDate'=>$this->input->post('plannedEndDate'),
			'estimatedDuration'=>$this->input->post('estimatedDuration')
		);
		$this->load->model('Project_management');
		;
		$data['success_message'] = '';
		if($this->Project_management->createProjectStage($project_data)){			
			$data['success_message'] .= 'You have created a new project stage!';
		}else{
			$data['success_message'] .= 'Something went wrong while creating the project stage!';	
		}
		$data['main_content'] = 'success_message';
		$this->load->view('layouts/general',$data);
	}
}
?>